package com.sure.minion;

import javax.annotation.Resource;

import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import com.sure.minion.web.interceptor.AuthInterceptor;

/**
 * srping mvc配置，设置拦截器、静态资源配置、国际化处理等
 *
 * @author huangjian
 * @date 2015-04-13
 */
@Configuration
@EnableWebMvc
public class WebAppMvcConfigurer extends WebMvcAutoConfigurationAdapter {
	@Resource
	AuthInterceptor authInterceptor;

	/**
	 * 设置自定义拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 国际化变化拦截器
//		LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
//		registry.addInterceptor(localeInterceptor);

		// 授权拦截器
//		registry.addInterceptor(authInterceptor);
	}

	/**
	 * 国际化解析器使用session解析
	 */
	@Bean
	public LocaleResolver localeResolver() {
		return new SessionLocaleResolver();
	}

	/**
	 * 对象到json的转换器，增加国际化操作.
	 */
//	@Bean
//	public GenericResultConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
//		/*******************************************************************
//		 * GenericResultConverter继承自MappingJackson2HttpMessageConverter.
//		 * 执行默认的json转换操作，只是在返回响应对象时做国际化处理
//		 *******************************************************************/
//		GenericResultConverter converter = new GenericResultConverter();
//		converter.setObjectMapper(objectMapper);
//		return converter;
//	}
}
